const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// 创建数据模型
const PostSchema = new Schema({
    user:{
        type:Schema.Types.ObjectId,
        ref:"users"
    },
    text:{
        type:String,
        required:true
    },
    name:{
        type:String,
    },
    avatar:{
        type:String,
    },
    likes:[
        {
            user:{
                type:Schema.Types.ObjectId,
                ref:"users"
            }
        }
    ],
    comments:[
        {
            date:{
                type:Date,
                default:Date.now
            },
            text:{
                type:String,
                required:true
            },
            user:{
                type:Schema.Types.ObjectId,
                ref:"users"
            },
            name:{
                type:String,
            },
            avatar:{
                type:String,
            }
        }
    ],
    date:{
        type:Date,
        default:Date.now
    }
})
module.exports = Post = mongoose.model("post",PostSchema);